//
//  RootViewController.m
//  TTDT_1
//
//  Created by lanou on 15/9/8.
//  Copyright (c) 2015年 zhengyl. All rights reserved.
//

#import "RootViewController.h"
#import "Define.h"
#import "MyView.h"
#import "MVView.h"
#import "MusicView.h"
#import "MiniMusicView.h"
#import "TitleView.h"
#import "EveryShotView.h"

@interface RootViewController ()<UIScrollViewDelegate, TitleViewDelegate>

@property (nonatomic, strong) UIScrollView *scrollView;
@property (nonatomic, strong) TitleView *titleView;

@end

@implementation RootViewController




- (void)viewDidLoad {
    [super viewDidLoad];
    
    //scrollView的高
    CGFloat height = kScreenHeight - kMusicHeight - kTitleHeight;
    //1.指定根视图
    self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, kTitleHeight, kScreenWidth, height)];
    self.scrollView.contentSize = CGSizeMake(kScreenWidth * 4, height);
    self.scrollView.pagingEnabled = YES;
    self.scrollView.showsHorizontalScrollIndicator = NO;
    self.scrollView.showsVerticalScrollIndicator = NO;
    self.scrollView.delegate = self;
    [self.view addSubview:self.scrollView];
    
    //2,添加我的,听,MV分类,每日一发三个子视图
    MyView *myView = [[MyView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, height)];
    myView.backgroundColor = [UIColor yellowColor];
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 30)];
    label.text= @"我的";
    [myView addSubview:label];
    [self.scrollView addSubview:myView];
    
    MusicView *musicView = [[MusicView alloc] initWithFrame:CGRectMake(kScreenWidth, 0, kScreenWidth, height)];
    musicView.backgroundColor = [UIColor whiteColor];
    UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 30)];
    //label1.text= @"听";
    [musicView addSubview:label1];
    [self.scrollView addSubview:musicView];
    
    MVView *mvView = [[MVView alloc] initWithFrame:CGRectMake(kScreenWidth * 2, 0, kScreenWidth, height)];
    mvView.backgroundColor = [UIColor redColor];
    UILabel *label2 = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 30)];
    label2.text= @"MV分类";
    [mvView addSubview:label2];
    [self.scrollView addSubview:mvView];
    
    EveryShotView *everyShotView = [[EveryShotView alloc] initWithFrame:CGRectMake(kScreenWidth * 3, 0, kScreenWidth, height)];
    everyShotView.backgroundColor = [UIColor whiteColor];
    UILabel *label3 = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 30)];
    label3.text= @"每日一发";
    [everyShotView addSubview:label3];
    [self.scrollView addSubview:everyShotView];
    
    //3,添加mini音乐播放试图
    MiniMusicView *miniMusicView = [[MiniMusicView alloc] initWithFrame:CGRectMake(0, kScreenHeight - kMusicHeight, kScreenWidth, kMusicHeight)];
    miniMusicView.backgroundColor = [UIColor blueColor];
    [self.view addSubview:miniMusicView];

    //4,头标题视图
    self.titleView = [[TitleView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kTitleHeight)];
    self.titleView.backgroundColor = [UIColor grayColor];
    self.titleView.delegate = self;
    [self.view addSubview:self.titleView];

}


#pragma mark-=-=-=-=-=TitleView代理方法的实现
-(void)touchview{
    
    [self.scrollView setContentOffset:CGPointMake(0, 0)];
    self.titleView.myBtn.image.hidden = NO;
    self.titleView.listenBtn.image.hidden = YES;
    self.titleView.categoryBtn.image.hidden = YES;
    self.titleView.dayBtn.image.hidden = YES;
}
-(void)touchB{
    
    [self.scrollView setContentOffset:CGPointMake(kScreenWidth, 0)];
    self.titleView.myBtn.image.hidden = YES;
    self.titleView.listenBtn.image.hidden = NO;
    self.titleView.categoryBtn.image.hidden = YES;
    self.titleView.dayBtn.image.hidden = YES;
}

-(void)touchM{
    
    [self.scrollView setContentOffset:CGPointMake(2 * kScreenWidth, 0)];
    self.titleView.myBtn.image.hidden = YES;
    self.titleView.listenBtn.image.hidden = YES;
    self.titleView.categoryBtn.image.hidden = NO;
    self.titleView.dayBtn.image.hidden = YES;
}

-(void)touchE{
    
    [self.scrollView setContentOffset:CGPointMake(3 * kScreenWidth, 0)];
    self.titleView.myBtn.image.hidden = YES;
    self.titleView.listenBtn.image.hidden = YES;
    self.titleView.categoryBtn.image.hidden = YES;
    self.titleView.dayBtn.image.hidden = NO;
}

#pragma mark=-=-=-=-=-=scrollView代理方法的实现
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    
    if (self.scrollView.contentOffset.x == 0) {
        self.titleView.myBtn.image.hidden = NO;
        self.titleView.listenBtn.image.hidden = YES;
        self.titleView.categoryBtn.image.hidden = YES;
        self.titleView.dayBtn.image.hidden = YES;
    }
    if (self.scrollView.contentOffset.x == kScreenWidth) {
        self.titleView.myBtn.image.hidden = YES;
        self.titleView.listenBtn.image.hidden = NO;
        self.titleView.categoryBtn.image.hidden = YES;
        self.titleView.dayBtn.image.hidden = YES;
    }
    if (self.scrollView.contentOffset.x == 2 * kScreenWidth) {
        self.titleView.myBtn.image.hidden = YES;
        self.titleView.listenBtn.image.hidden = YES;
        self.titleView.categoryBtn.image.hidden = NO;
        self.titleView.dayBtn.image.hidden = YES;
    }
    if (self.scrollView.contentOffset.x == 3 * kScreenWidth) {
        self.titleView.myBtn.image.hidden = YES;
        self.titleView.listenBtn.image.hidden = YES;
        self.titleView.categoryBtn.image.hidden = YES;
        self.titleView.dayBtn.image.hidden = NO;
    }
}


@end
